checkToken();
function checkToken() {
	var systoken = sessionStorage.getItem('systoken');
	if(!systoken) {
		alert("请先登录!")
		window.location.href = "../../login.html"
	}
}
var urlA = path + "/theoryRecords/getAll";
//获取学员理论课培训记录
layui.use(['table', 'laypage', 'layer', 'laydate', 'jquery','form'], function() {
	 var form = layui.form
    	var laydate = layui.laydate;
        var $ = layui.$
        
    laydate.render({
        elem: '.updateTime'
        ,
        type: 'datetime'
    });
    //日期时间选择器
    laydate.render({
        elem: '.createTime',
        type: 'datetime'
    });
		form.on("select(pid)",function(){
		            if($(".type  option:selected").val()=="0"){
                        $("#kemu").find("option").remove();
                        $("#kemu").append( "<option value=\"\">请选择培训科目</option>",
                            "<option value=\"0\">雷达管制基础模拟机</option>",
                            "<option value=\"1\">机场管制基础模拟机</option>",
                            "<option value=\"2\">程序管制基础模拟机</option>"
                        );
		                $(".bianhao").css("display","block")
		                urlA = path + "/operationRecords/getAll";
		                getShiCao();
		            }else{
		                $(".bianhao").css("display","none")
		                urlA = path + "/theoryRecords/getAll";
                        $("#kemu").find("option").remove();
                        $("#kemu").append(
                            "<option value=\"\">请选择培训科目</option>",
                            "<option value=\"0\">雷达管制理论</option>",
                            "								<option value=\"1\">机场管制理论</option>",
                            "								<option value=\"2\">程序管制理论</option>",
                            "								<option value=\"3\">空管基础理论</option>"
					)
		                getTheoryRecord();
		            }
            form.render('select');
		        })
})

$(".startSearch").click(function() {
		        if($(".type  option:selected").val()=="0"){
		           getShiCao();
		        }else{
		           getTheoryRecord();  
		        }


		});

getTheoryRecord();
function getShiCao() {
	layui.use(['table', 'laypage', 'layer', 'laydate', 'jquery','form'], function() {
		var laypage = layui.laypage,
            form = layui.form,
			layer = layui.layer,
			$ = layui.jquery;
		var table = layui.table;
		var laydate = layui.laydate;
		var name = sessionStorage.getItem('name');
		var theoryName = $(".theoryName").val();
		var operationType = $(".theoryType option:selected").val();
		var trainingType = $(".trainingType option:selected").val();
		var type = $(".type option:selected").val();
		var startTime = $(".startTime").val();
		var endTime = $(".endTime").val();
		var param = {
			type:type,
            trainingType:trainingType,
			studentName: name,
			endTime:endTime,
			startTime:startTime,
            operationType: operationType,
			theoryName: theoryName,
			stamp: new Date().getTime(),
			version: 0,
			visit_plat: 1,
			visit_type: 0,
			is_used: 0
		};
       
		var defaultpageSise = 10;
		window.ins1 = _render(defaultpageSise);

		function _render(pageSize) {
			var width = $(document).width();
			table.render({
				elem: '#lilunpTest',
				height: 600,
				title: '模拟机培训记录',
				method: 'post',
				url: urlA,
				page: true,
				where: {param: JSON.stringify(param)},
				headers: {Authorization: sessionStorage.getItem('systoken')},
				skin: 'row',
				even: true,
				loading: true,
				parseData: function(res) {

					for(var i = 0 ; i< res.rows.length ; i ++){
						
						
                        res.rows[i].courseType='模拟机课'
						if(res.rows[i].operationType == "0"){
                            res.rows[i].operationType = "雷达管制基础模拟机"
						}else if (res.rows[i].operationType == "1") {
                            res.rows[i].operationType = "机场管制基础模拟机"
						} else if (res.rows[i].operationType == "2") {
                            res.rows[i].operationType = "程序管制基础模拟机"
                        }else if (res.rows[i].operationType == "3") {
                            res.rows[i].operationType = "雷达管制基础模拟机"
                        }

                        if(res.rows[i].trainingType == "0"){
                            res.rows[i].trainingType = "岗前培训"
                        }else if (res.rows[i].trainingType == "1") {
                            res.rows[i].trainingType = "岗位培训"
                        } else if (res.rows[i].trainingType == "2") {
                            res.rows[i].trainingType = "复习"
                        }else if (res.rows[i].trainingType == "3") {
                            res.rows[i].trainingType = "熟练"
                        }else if (res.rows[i].trainingType == "4") {
                            res.rows[i].trainingType = "附加"
                        }else if (res.rows[i].trainingType == "5") {
                            res.rows[i].trainingType = "补习"
                        }else if (res.rows[i].trainingType == "6") {
                            res.rows[i].trainingType = "追加"
                        }


					}
					return {
						"code": res.status,
						"msg": res.rows,
						"count": res.total,
						"data": res.rows
					};
				},
				done: function(res) {
				},
				totalRow: true,
				limit: 30,
				width: width * 0.9,
				cols: [
					[
                        {field: 'courseType', title: '课程类型', width: '30%', align: 'center'},
                        {field: 'trainingType', title: '培训类别', width: '30%', align: 'center'},
						{field: 'operationType', title: '培训科目', width: '30%', align: 'center'},
						{field: 'teacherName', title: '教员姓名', width: '30%', align: 'center'},
						{field: 'number', title: '练习编号', width: '30%', align: 'center'},
						{field: 'standardCall', title: '得分', width: '30%', align: 'center'},
						{field: 'startTime', title: '开始时间', width: '100', align: 'center'},
						{field: 'createTime', title: '结束时间', width: '100', align: 'center'},
						{field: 'time', title: '时长（分钟）', width: '100', align: 'center'},
					]
				],
				page: true,
				limits: [10, 20, 30, 40, 50, 100],
				limit: pageSize,
				loading: true
			});
		};
	});
}








function getTheoryRecord(){
	layui.use(['table', 'laypage', 'layer', 'laydate', 'jquery','form'], function() {
		var laypage = layui.laypage,
            form = layui.form,
			layer = layui.layer,
			$ = layui.jquery;
		var table = layui.table;
		var laydate = layui.laydate;
		var name = sessionStorage.getItem('name');
		var theoryName = $(".theoryName").val();
		var theoryType = $(".theoryType option:selected").val();
		var trainingType = $(".trainingType option:selected").val();
		var type = $(".type option:selected").val();
		var startTime = $(".startTime").val();
		var endTime = $(".endTime").val();
		var param = {
			type:type,
            trainingType:trainingType,
			studentName: name,
			endTime:endTime,
			startTime:startTime,
			theoryType: theoryType,
			theoryName: theoryName,
			stamp: new Date().getTime(),
			version: 0,
			visit_plat: 1,
			visit_type: 0,
			is_used: 0
		};
       
		var defaultpageSise = 10;
		window.ins1 = _render(defaultpageSise);

		function _render(pageSize) {
			var width = $(document).width();
			table.render({
				elem: '#lilunpTest',
				height: 600,
				title: '理论课培训记录',
				method: 'post',
				url: urlA,
				page: true,
				where: {param: JSON.stringify(param)},
				headers: {Authorization: sessionStorage.getItem('systoken')},
				skin: 'row',
				even: true,
				loading: true,
				parseData: function(res) {
					// console.log(res)


//layer.open({type:3, time:4000,end:function(){
//				parent.layer.closeAll();
//			}});
					for(var i = 0 ; i<res.rows.length;i++){
                        res.rows[i].courseType='理论课'
						// console.log(res.rows[i].theoryType)
							if(res.rows[i].theoryType == "0"){
                                res.rows[i].theoryType = "雷达管制理论"
							}else if(res.rows[i].theoryType == "1"){
                                res.rows[i].theoryType = "机场管制理论"
							}else if(res.rows[i].theoryType == "2"){
                                res.rows[i].theoryType = "程序管制理论"
							}else if(res.rows[i].theoryType == "3"){
                                res.rows[i].theoryType = "空管基础理论"
							}

							if(res.rows[i].trainingType == "0"){
	                            res.rows[i].trainingType = "岗前培训"
	                        }else if (res.rows[i].trainingType == "1") {
	                            res.rows[i].trainingType = "岗位培训"
	                        } else if (res.rows[i].trainingType == "2") {
	                            res.rows[i].trainingType = "复习"
	                        }else if (res.rows[i].trainingType == "3") {
	                            res.rows[i].trainingType = "熟练"
	                        }else if (res.rows[i].trainingType == "4") {
	                            res.rows[i].trainingType = "附加"
	                        }else if (res.rows[i].trainingType == "5") {
	                            res.rows[i].trainingType = "补习"
	                        }else if (res.rows[i].trainingType == "6") {
	                            res.rows[i].trainingType = "追加"
	                        }


					}

					return {
						"code": res.status,
						"msg": res.rows,
						"count": res.total,
						"data": res.rows
					};
				},
				done: function(res) {
				},
				totalRow: true,
				limit: 10,
				width: width * 0.9,
				cols: [
					[
                        {field: 'courseType', title: '课程类型', width: '30%', align: 'center'},
                        {field: 'trainingType', title: '培训类别', width: '30%', align: 'center'},
						{field: 'theoryType', title: '培训科目', width: '30%', align: 'center'},
						{field: 'teacherName', title: '教员姓名', width: '30%', align: 'center', },
						{field: 'content', title: '内容', width: '30%', align: 'center'},
						{field: 'createTime', title: '开始时间', width: '105', align: 'center'},
						{field: 'updateTime', title: '结束时间', width: '105', align: 'center'},
						{field: 'time', title: '时长（分钟）',width: '100', align: 'center'},
					]
				],

				limits: [10, 20, 30, 40, 50, 100],
				// limit: pageSize,
				// loading: true
			});
		};
	});
}